import { BaseModel } from '@/common/base/base.model';
import { Column, Entity, JoinColumn, ManyToOne } from 'typeorm';
import { AdminModel } from "@/module/admin/admin.model";
import { RoleModel } from "@/module/role/role.model";
import { ResourceModel } from "@/module/resource/resource.model";

@Entity('ROLE_RESOURCE', {
  synchronize: false,
}) // 角色与权限的中间表
export class RoleResourceModel extends BaseModel {
  @Column({
    comment: '角色uuid',
    type: 'uuid',
  })
  roleUuid: string;
  @ManyToOne(() => RoleModel,{
    createForeignKeyConstraints: false,
  })
  @JoinColumn({
    name: 'role_uuid',
    referencedColumnName: 'uuid',
  })
  role: AdminModel;

  @Column({
    comment: '权限uuid',
    type: 'uuid',
  })
  resourceUuid: string;
  @ManyToOne(() => ResourceModel,{
    createForeignKeyConstraints: false,
  })
  @JoinColumn({
    name: 'resource_uuid',
    referencedColumnName: 'uuid',
  })
  resource: ResourceModel;
}
